<?php
/*
***
***访问统计
***
*/
class ViewAction extends Action{
	public function goods_count($id,$url){
		$Member=M('Member');
		$Views=M('Views');
		import('ORG.Net.IpLocation');// 导入IpLocation类
		$Ip = new IpLocation('UTFWry.dat'); // 实例化类 参数表示IP地址库文件
		$area = $Ip->getlocation(); // 获取某个IP地址所在的位置
		$user=session('euname');
		if(!empty($user)){
			$map['uname']=$user;
			$member=$Member->where($map)->find();
			$data2['member_id']=$member['member_id'];
			$data['member_id']=$member['member_id'];
		}
		$map2['goods_id']=$id;
		$map2['ip']=$area['ip'];
		//$map2['acttime']=$array();

		$ck=$Views->where($map2)->find();
		if(true==$ck){
			$data['acttime']=time();
			$data['view_count']=$ck['view_count']+1;
			$Views->where('id='.$ck['id'])->save($data);
		}else{
			$data2['goods_id']=$id;
			$data2['acttime']=time();
			$data2['view_count']=1;
			$data2['com_url']=$url;
			$data2['ip']=$area['ip'];
			$data2['area']=$area['area'];
			$Views->add($data2);
		}
	}

}